package designpatterns.facade.code;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;

/**
 * @description: 文件读取
 * @date: 2023-02-02 17:47
 */
public class FileReader {

    public String read(String fileNameSrc) {
        System.out.println(String.format("读取文件=>fileNameSrc=%s", fileNameSrc));
        FileInputStream fs = null;
        StringBuilder sb = new StringBuilder();
        try {
            fs = new FileInputStream(fileNameSrc);
            int data;
            while ((data = fs.read()) != -1) {
                sb = sb.append((char) data);
            }
        } catch (Exception e) {
            System.err.println("文件读取失败！");
        } finally {
            if (Objects.nonNull(fs)) {
                try {
                    fs.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }

}
